<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4
 * Time: 15:45
 */
include "../conn.php";
header('Content-Type:text/html;charset=UTF-8');
//获取管理员资料数据
$AdministratorId = $_GET['AdministratorId'];
$AdministratorName = urldecode($_GET['AdministratorName']);


//获取学生资料数据
$StudentId = $_GET['StudentId'];
$StudentPassword = urldecode($_GET['StudentPassword']);
$StudentName = urldecode($_GET['StudentName']);

$Sex = $_GET['Sex'];
$Class = $_GET['Class'];
$Tel = $_GET['Tel'];
$email = $_GET['email'];
$QQ = $_GET['QQ'];
$Depart = $_GET['Depart'];

//获取教师资料数据
$TeacherId = $_GET['TeacherId'];
$TeacherPassword = $_GET['TeacherPassword'];
$TeacherName = urldecode($_GET['TeacherName']);

//修改的用户类型
$usertype = $_GET['saved'];

//修改学生资料数据
if ($usertype == 's-change') {
    $sql = "update student set StudentId='$StudentId',StudentName='$StudentName',Sex='$Sex',
	          Tel='$Tel',Class='$Class',email='$email',QQ='$QQ',Major='$Depart'
	           where StudentId='$StudentId'";

    if (mysqli_query($conn, $sql)) {
        echo("修改成功");
    } else {
        echo("修改失败");
    }
}

//修改教师资料数据
if ($usertype == 't-change') {
    $sql = "update teacher set TeacherId='$TeacherId',TeacherName='$TeacherName',
			  Sex='$Sex',Tel='$Tel',QQ='$QQ',Depart='$Depart',email='$email'
		      where TeacherId='$TeacherId'";

    if (mysqli_query($conn, $sql)) {
        echo("修改成功");
    } else {
        echo $sql . error_get_last();
        echo("修改失败");
    }
}

//修改管理员资料数据
if ($usertype == 'a-change') {
    $sql = "update administrator set 	AdministratorId='$AdministratorId',AdministratorName='$AdministratorName',
			  Sex='$Sex',Tel='$Tel',email='$email',QQ='$QQ',Depart='$Depart'
			  where AdministratorId='$AdministratorId'";

    if (mysqli_query($conn, $sql)) {
        echo("修改成功");
    } else {
        echo("修改失败");
    }
}


if ($_POST['manage']=='manage') {
    $TeacherId = $_POST['TecherId'];
    $selectStudent = $_POST['selectStudent'];
    $selectType = $_POST['selectType'];


    //教师添加学生
    if ($selectType == 't-addStudnet') {
        $check = "select * from student where StudentId=$selectStudent";
        $result = mysqli_query($conn, $check);
        if ($result->num_rows > 0) {
            $sql = "update student set Teacher_TeacherId=$TeacherId where StudentId=$selectStudent";
            if (mysqli_query($conn, $sql)) {
                echo "添加学生成功！";
            } else echo "添加学生失败";
        } else {
            echo("不存在这个学生，/n/n请输入正确的11位学生学号！");
        }
    }


    //教师删除学生
    if ($selectType == 't-deleteStudnet') {
            $sql = "update student set Teacher_TeacherId=NULL where StudentId=$selectStudent";
            if (mysqli_query($conn, $sql)) {
                echo "删除学生成功！";
            }else echo "删除学生失败";
        }
}





?>






